package com.cs.mq;

import java.util.Hashtable;

import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.CMQC;

/**
 * @author Sam.Lee
 * @version Created：Feb 26, 2013 10:54:30 AM
 */
public class MQPutMessage {
	public static void main(String[] args) throws Exception {
		MQQueueManager queueManager = null;
		MQQueue mqQueue = null;

		try {
			String pstrCorrelationID = null;

			Hashtable<String, Object> properties = new Hashtable<String, Object>();
			properties.put("hostname", "localhost");
			properties.put("port", 1414);
			properties.put("channel", "ESP");
			// IBM Coded Character Set Identifiers (CCSID)
			properties.put("CCSID", 1381);
			properties.put("userID", "administrator");
			properties.put("password", "942249");
			queueManager = new MQQueueManager("MQHA", properties);
			mqQueue = queueManager.accessQueue("EETOESP", CMQC.MQOO_INPUT_AS_Q_DEF
					| CMQC.MQOO_OUTPUT, null, null, null);
			MQMessage mqMessage = new MQMessage();
			//if (pstrCorrelationID != null) {
				// mqMessage.correlationId = Base64
				// .base64ToByteArray(pstrCorrelationID);
			//}
			mqMessage.writeString("test message...");
			mqQueue.put(mqMessage, new MQPutMessageOptions());
			byte[] bytesMessageID = mqMessage.messageId;
			// return Base64.byteArrayToBase64(bytesMessageID);
		} catch (Exception e) {
			throw e;
		} finally {
			if (mqQueue != null) {
				mqQueue.close();
			}
			if (queueManager != null) {
				queueManager.disconnect();
			}
		}
	}
}
